package com.scrx.ymg.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.scrx.ymg.entity.Address;
import com.scrx.ymg.service.address.IAddressService;

@Controller
@RequestMapping("/addressAction")
public class AddressAction {
	
	@Autowired
	private IAddressService adds;
	/**
	 * 根据用户id得到地址
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value ="/getAddress",produces = "text/json;charset=UTF-8")
	public String getAddress(String userID){
		List<Address> list= adds.getAddress(userID);
		Gson gson = new Gson();
		if (list!=null) {
			return gson.toJson(list);
		}
		return "false";
	}
	
	/**
	 * 根据用户id得到所有地址
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value ="/getAllAddress",produces = "text/json;charset=UTF-8")
	public String getAllAddress(String userID){
		List<Address> list= adds.getAllAddress(userID);
		Gson gson = new Gson();
		if (list!=null) {
			return gson.toJson(list);
		}
		return "false";
	}
	
	/**
	 * 根据地址id得到地址
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value ="/getAddressOne",produces = "text/json;charset=UTF-8")
	public String getAddressOne(String addID){
		Address list= adds.getAddressByID(addID);
		Gson gson = new Gson();
		if (list!=null) {
			return gson.toJson(list);
		}
		return "false";
	}
	
	/**
	 * 根据用户id得到地址
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value ="/getAddressByUserAndSuperID",produces = "text/json;charset=UTF-8")
	public String getAddressByUserAndSuperID(String userID,String superID){
		Address list= adds.getAddress(userID,superID);
		Gson gson = new Gson();
		if (list!=null) {
			return gson.toJson(list);
		}
		return "false";
	}
	/**
	 * 根据地址id删除地址
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value ="/deleteAddressByAddId",produces = "text/json;charset=UTF-8")
	public String deleteAddressByAddId(String addId){
		return adds.deleteAddress(addId);
	}
}
